<?php

namespace App\Http\Controllers\Api;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\Error;

class ErrorController extends Controller
{
    //
    /**
     * 新增错误记录
     *
     * @ author: zrc
     * @ E-mail:904725327@qq.com
     * @ date: 2018/7/12
     * @access public|private|protected
     * @param  mixed    name    comment
     * @param  int    name    comment
     * @param  string    name    comment
     * @param  bool       name    comment
     * @param  array   name    comment
     * @return void|int|string|boolean|array        comment
     */
    public function error_log(Request $request){
        $info = $request->all();
        $field = ['uid','OS_Version','SDK_Version','vendor','APP_Version','ex_info','type'];
        if (empty($info['type']))
            return respF(1003);
        $data = [];
        foreach ($field as $value){
            if (!empty($info[$value])){
                $data[$value] = $info[$value];
//                if ($value == 'uid') {
//                    $data['uid'] = $info[$value];
//                }
            }
        }
        $data['time'] = time();
        if($re = Error::insert($data)){
            return response()->json(['status' => 1, 'msg' => '添加成功']);
        }else{
            return respF(1000);
        }
    }
}
